/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package operators;

import metadata.TableMetaData;

/**
 *
 * @author Dragan
 */
public class TableAccess extends Operation {

    protected TableMetaData tableMetaData;
    protected long inputSize;
    protected double selectivityofPredicate;

    public TableAccess(TableMetaData tableMetaData, long inputSize, double selectivityofPredicate) {
        this.tableMetaData = tableMetaData;
        this.inputSize = inputSize;
        this.selectivityofPredicate = selectivityofPredicate;
        this.operationName = "TableAccess";
        execute();
    }

    public TableAccess(TableMetaData tableMetaData, long inputSize) {
        this(tableMetaData, inputSize, 1.0);
    }

    @Override
    protected void execute() {
        long np = tableMetaData.getNumberOfDiskPages();
        diskCost = (long) (np * (1 - Math.pow(1 - 1 / np, inputSize)));
        outputSize = (long) (inputSize * selectivityofPredicate);
    }

    @Override
    public String toString() {
        String str = " t:" + tableMetaData.getTableName() + " input:" + this.inputSize;
        return this.operationName + str + " " + super.toString();
    }
}
